FAQ for TSMDBGrid component
1. How I can add the sorted column?
SMDBGrid.DataSource.DataSet.DisableControls; {add a new sorted column in list - ascending order} with SMDBGrid.SortColumns.Add do begin FieldName := 'yourFieldName'; SortType := stAscending end; {add a new sorted column in list - descending order} with SMDBGrid.SortColumns.Add do begin FieldName := 'yourFieldName'; SortType := stDescending; end; SMDBGrid.DataSource.DataSet.EnableControls;
2. How I can clear the all sorted columns?
SMDBGrid.DataSource.DataSet.DisableControls; {clear the all sorted columns} SMDBGrid.SortColumns.Clear; SMDBGrid.DataSource.DataSet.EnableControls;
3. How I can change a standard TSMDBGrid glyphs (sorted arrows, indicator symbols etc)?
You can run the Image Editor application (or any other resource workshop), open the SMDBGrid.RES file and change the any glyphs.
4. How I can change standard strings for messages?
In SMCnst.PAS file you can find the any string resource and change it or traslate on new language. In this file you can find the strings for English, Russian, Ukrainian, French, German, Italian and Japan languages. If you have translated the messages to the new language or have corrected an mistake, send the changed file to me mailto:mshkolnik@scalabium.com, mshkolnik@yahoo.com) and I shall include it in the new build.
5. How I can increase a Indicator column width?
For it's necessary to change value of WidthOfIndicator property.
Pay attantion to that width cann't be less than 11 (width of indicator in standard TDBGrid). Also if you include a eoCheckBoxSelect flag in ExOptions property for record selecting by checkbox, then minimum value is width of standard checkbox in a current Windows settings.
6. How I can display the images in Indicator column?
Write an OnGetGlyph event handler to provide customized drawing for the data in the Indicator column. You can define a glyph, which will be displayed. And, of course, this event will be called for each row and you can define the other glyphs for records.
Pay attantion to that Indicator width will not be automatically increased, if the glyph will not be located in cell. You should set width of Indicator column in view of other information, which will be displayed there (checkbox for record selection, row state glyph etc).
In current version you can assign the bitmap only but in future I plan to add the any graphics (icons, metafile, jpeg etc)
7. How I can display the multi-line captions for columns?
This feature is supported automatically - when you change a width of any column or add/remove the sorted type in column, width of columns will be recalculate automatically and if it's necessary title height will change!
8. I want display the pictures in cells for graphic fields. How I can do it?
Simply set a eoDrawGraphicField flag in ExOptions property.
9. How I can assign the operations to standard menu items?
For each item in standard menu are created events:
All this events very useful for creation of user interface. For example, you can assign a procedure for append record, in which you will create a new form with controls for filling fields. And always your user will be append the record in your form (irrespective of the fact how he has come in an append record mode).
Pay attantion to that if you not assigned the some events, then in standard popup menu will be deleted the same items!
10. Can I use a standard popup menu and add the custom popup?
Yes, of course. When you included the eoStandardPopup flag in ExOptions property, the standard popup will be displayed by right button mouse click. But if you assigend the custom popup in Popup property then the standard popup will be displayed by click in "dropdown" cell only (the first cell in title row of Indicator column).
11. I want to prohibit append and/or delete of records in TSMDBGrid.
To include a eoDisableInsert and/or eoDisableDelete flag in ExOptions property.
12. Whether it's possible to fix a some columns?
Yes, of course. See a FixedCols and FixedColor properties.
Also if you want to fix columns, but to save their attributes, see a eoFixedLikeColumn flag in ExOptions property.
13. I want to display a hint for each cell.
If you want to display a hint, which contains the full string wholly which is not located on cell width, include a eoCellHint flag in ExOptions property. In this case with hit of a mouse pointer on any cell there will be a hint, containing full text with field value.
PS: if the field value is located in cell completely, the hint does not occur.
14. How I can insert a checkbox in cells?
If you included the eoBooleanAsCheckBox flag in ExOptions property, then for any boolean field the user can view and edit field values in checkboxs.
15. I want to display a dropdown and ellipsis buttons in cells.
If you included the eoShowLookup flag in ExOptions property, then for each row of each columns (which have an assigned PickList, or ButtonStyle = cbsEllipsis, or assigned field is a Lookup-field) will be displayed the buttons (dropdown arrow or ellipsis). You can click on it for calling linked event.
PS: in standard TDBGrid these buttons occur only in editor mode.
16. My users want use Enter key like TAB for column naviagtion.
Set the eoENTERlikeTAB flag in ExOptions property.
Yes, see an OnDrawColumnTitle event.
18. I want to draw a rows in other colors.
If you want to draw a rows in TSMDBGrid you can do it in other way.
The first way - very-very simply: you can write in OnGetCellParams event the procedure, in which you check the some condition (for example, value in same field) and change a font or backcolor.
Example 1:
procedure TForm1.SMDBGrid1GetCellParams(Sender: TObject; Field: TField; AFont: TFont; var Background: TColor; Highlight: Boolean); begin {if CustNo less than 15, then set a bold font and red color in background} if Assigned(Field) and (UpperCase(Field.FieldName) = 'CUSTNO') then begin if Field.AsInteger < 15 then begin AFont.Style := [fsBold]; Background := clRed; end else begin AFont.Style := []; Background := clWhite; end end end;
The second way: you can write in OnDrawColumnCell event the procedure, in which you check the condition and draw on canvas. In this case you can realize the anything that you want - to draw shapes, images, to change a fonts and/or colors, to change a text position etc.
Example 2:
procedure TForm1.SMDBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin {if CustNo is 13 and is a second column, then draw image and text after it} if (Table1.FieldByName('CustNo').AsInteger = 13) and (DataCol = 2) then begin SMDBGrid1.Canvas.FillRect(Rect); SMDBGrid1.Canvas.Draw(Rect.Left, Rect.Top, Image1.Picture.Bitmap); SMDBGrid1.Canvas.TextOut(Rect.Left+20, Rect.Top+20, Column.Field.FieldName); end; end;
19. I want to change a color for odd rows.
As I described in previous topic you can do it in OnGetCellParams or OnDrawColumnCell events. For example:
procedure TForm1.SMDBGrid1GetCellParams(Sender: TObject; Field: TField; AFont: TFont; var Background: TColor; Highlight: Boolean); begin if (Table1.RecNo mod 2 = 1) then Background := clRed; end;
PS: of course, RecNo is valid for local tables only (Paradox, DBase etc). For SQL tables or queries you need do it with someelse method.
20. How I can receive the latest news about TSMDBGrid, new builds and upgrades?
If you want to receive the latest news about TSMDBGrid development and new versions of it, then send a message to me mailto:mshkolnik@scalabium.com, mshkolnik@yahoo.com or sign a gustbook) and I shall inform you about all changes.
Also I created the mailing list (http://www.onelist.com/subscribe/SMComponents). In this list you can discuss the questions connected to my components and/or applications (TSMDBGrid too, of course), receive the lastest news about development, propose the new features, receive the updates, new versions and bug fixings. Also there you can take the answer on any Delphi programming question.
Download a lastest version: smdbgrid.zip .(35Kb)
Last update: June 03, 2002